﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GbmpModel.h"
#include "UniIdentity.h"
#include "IParameterValueList.h"
#include "IParameterValueStorage.h"
#include "NdbObjectSchematic.h"
#include "DbDataSchema.h"

namespace gcmp
{
    class IDocument;
    class IParameterValueStorage;
    class IElement;

    class GBMP_MODEL_EXPORT GbmpParameterValueListBase :public NdbObjectSchematic, public IParameterValueList
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, GbmpParameterValueListBase, gcmp::NdbObjectSchematic, 032335A2 - C49B - 4DF4 - 8193 - 2B755C7D64D8, gbmpmodel, gcmp::IParameterValueList)
            DATA(UniIdentity, Uid)
            DATA_TRANSIENT(IElement*, pOwnerElement)
        DBOBJECT_DATA_END
    public:
        GbmpParameterValueListBase(const UniIdentity& uid) : m_Uid(uid), m_pOwnerElement(nullptr) {};
        virtual ~GbmpParameterValueListBase() {};

        virtual OwnerPtr<IParameterValueList> Clone() const override;
        virtual bool IsManualInputModifiable(const IDocument* pDoc) const override;

        const UniIdentity& GetUid() const override { return GetUid__(); }

        std::wstring GetDisplayStringByValue(const IDocument* pDoc, const IParameterValueStorage* pValue, const std::vector<ElementId>& ids = std::vector<ElementId>()) const override;
        OwnerPtr<IParameterValueStorage> GetValueByDisplayString(const IDocument* pDoc, const std::wstring& displayString, const std::vector<ElementId>& ids = std::vector<ElementId>()) const override;
        std::vector<std::wstring> GetDisplayStrings(const IDocument* pDoc, const std::vector<ElementId>& ids = std::vector<ElementId>()) const override;
        std::vector<OwnerPtr<IParameterValueStorage>> GetValues(const IDocument* pDoc, const std::vector<ElementId>& ids = std::vector<ElementId>()) const override;
        virtual bool HasOuterEditor() const override { return false; }

        bool SetOwnerElement(IElement* pOwnerElement);
        const IElement* GetOwnerElement() const;
        IElement* GetOwnerElement();

        static const std::wstring s_nullName;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override;
    protected:
        virtual std::wstring OnGetDisplayStringByValue(const IDocument* pDoc, const IParameterValueStorage* pValue) const;
        virtual OwnerPtr<IParameterValueStorage> OnGetValueByDisplayString(const IDocument* pDoc, const std::wstring& displayString, const std::vector<ElementId>& ids) const;
        virtual std::vector<OwnerPtr<IParameterValueStorage>> OnGetValues(const IDocument* pDoc, const std::vector<ElementId>& ids = std::vector<ElementId>()) const;
    };
}
